//
//  MCNewZhuanZhangViewController.m
//  LDYL
//
//  Created by MC on 2018/6/13.
//  Copyright © 2018年 TLYL01. All rights reserved.
//

#import "MCNewZhuanZhangViewController.h"
#import "MCThirdPartyShowInfoModel.h"
#import "MCGetThirdPartyBalanceModel.h"
#import "MCPaySelectedLotteryPickView.h"
#import "MCGetThirdPartyBalanceModel.h"
#import "MCUserMoneyModel.h"
#import "MCThirdPartyToTransferModel.h"
#import "MCThdLoginModel.h"
#import "MCMathUnits.h"

#define TIP  @"温馨提示：\n户内转账是自己的资金转入不同的平台，资金还是属于用户本人的，没有手续费和次数限制，您可以随意进行转账操作。"

#define FONTTIP  11

#define UILABEL_LINE_SPACE 5
#define UILABEL_Kern_SPACE 0.1
#define L_SPACE 15

#define ZhuanZhangMaxMoney  50000

@interface MCNewZhuanZhangViewController ()

@property (nonatomic,strong) MCThirdPartyShowInfoModel * thirdPartyShowInfoModel;

@property (nonatomic,strong) UILabel * yuENum1;
@property (nonatomic,strong) UIButton * btn_Search1;

@property (nonatomic,strong) UILabel * yuENum2;
@property (nonatomic,strong) UIButton * btn_Search2;

@property (nonatomic,strong) UITextField * moneyTf;
@property (nonatomic,strong) UITextField * mimaTf;

@property (nonatomic,strong) UILabel * lab_tip;

@property (nonatomic,strong) MCShowInfoModel * selected1;
@property (nonatomic,strong) MCShowInfoModel * selected2;

@property (nonatomic,strong) NSString * Balance;

@property (nonatomic,strong) MCGetThirdPartyBalanceModel * getThirdPartyBalanceModel;

@property (nonatomic,strong) MCUserMoneyModel  * userMoneyModel ;

@property (nonatomic,strong) MCThirdPartyToTransferModel * thirdPartyToTransferModel;

@property (nonatomic,strong) MCThdLoginModel * thdLoginModel;

@property (nonatomic,assign)float DrawMaxMoney;

@end

@implementation MCNewZhuanZhangViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setUpUI];
    
    self.navigationItem.title = @"转账";
    self.view.backgroundColor = RGB(231, 231, 231);
    _DrawMaxMoney=ZhuanZhangMaxMoney;
}


-(void)viewWillAppear:(BOOL)animated{
    
    [super viewWillAppear:animated];
    
    self.navigationController.navigationBarHidden = NO;
    self.navigationController.navigationBar.translucent = NO;
    
    __weak __typeof__ (self) wself = self;
    
    MCThirdPartyShowInfoModel *thirdPartyShowInfoModel = [MCThirdPartyShowInfoModel sharedMCThirdPartyShowInfoModel];
    [thirdPartyShowInfoModel refreashDataAndShow];
    self.thirdPartyShowInfoModel=thirdPartyShowInfoModel;
    
    thirdPartyShowInfoModel.callBackSuccessBlock = ^(id manager) {
        
        [wself.thirdPartyShowInfoModel setDataWithDic:manager[@"TransferDirection"]];
        
    };
    
    thirdPartyShowInfoModel.callBackFailedBlock = ^(id manager, NSString *errorCode) {
        
    };
    
    //    wself.getThirdPartyBalanceModel.Balance=@"777";
    
    //  查询用户余额及冻结金额
    MCUserMoneyModel * userMoneyModel=[MCUserMoneyModel sharedMCUserMoneyModel];
    [userMoneyModel refreashDataAndShow];
    self.userMoneyModel=userMoneyModel;
    userMoneyModel.callBackSuccessBlock = ^(id manager) {
        
        wself.userMoneyModel.FreezeMoney = manager[@"FreezeMoney"];
        wself.userMoneyModel.LotteryMoney = manager[@"LotteryMoney"];
        
    };
    
}

-(void)setUpUI{
    
    //    XX余额1
    UIView * back = [[UIView alloc]init];
    back.backgroundColor=[UIColor clearColor];
    [self.view addSubview:back];
    [back mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view.mas_top).offset(0);
        make.left.equalTo(self.view.mas_left).offset(0);
        make.right.equalTo(self.view.mas_right).offset(0);
        make.width.mas_equalTo(83);
    }];
    
    UILabel * yuE1 = [[UILabel alloc] init];
    _yuENum1 = [[UILabel alloc] init];
    _btn_Search1=[[UIButton alloc] init];
    [self.view addSubview:_btn_Search1];
    [self SetUIWithBack:back andyuE1:yuE1 andyuENum1:_yuENum1 andZhuanChuBtn:_btn_Search1 andTag:1001];
    [_btn_Search1 addTarget:self action:@selector(btn_SearchAction:) forControlEvents:UIControlEventTouchUpInside];
    _btn_Search1.backgroundColor=[UIColor clearColor];
    [_btn_Search1 setTitleColor:RGB(46, 46, 46) forState:UIControlStateNormal];
    [_btn_Search1 setTitle:@"请选择" forState:UIControlStateNormal];
    _btn_Search1.tag=1001;
    _btn_Search1.titleLabel.font = [UIFont systemFontOfSize:14];
    _btn_Search1.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    _btn_Search1.frame=CGRectMake(100, 33, G_SCREENWIDTH-110, 50);
    
    
    //    XX余额2
    UIView * back2 = [[UIView alloc]init];
    back2.backgroundColor=[UIColor clearColor];
    [self.view addSubview:back2];
    [back2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view.mas_top).offset(83);
        make.left.equalTo(self.view.mas_left).offset(0);
        make.right.equalTo(self.view.mas_right).offset(0);
        make.width.mas_equalTo(83);
    }];
    UILabel * yuE2 = [[UILabel alloc] init];
    _yuENum2 = [[UILabel alloc] init];
    _btn_Search2=[[UIButton alloc] init];
    [self.view addSubview:_btn_Search2];
    [self SetUIWithBack:back2 andyuE1:yuE2 andyuENum1:_yuENum2 andZhuanChuBtn:_btn_Search2 andTag:1002];
    [_btn_Search2 addTarget:self action:@selector(btn_SearchAction:) forControlEvents:UIControlEventTouchUpInside];
    _btn_Search2.backgroundColor=[UIColor clearColor];
    [_btn_Search2 setTitleColor:RGB(46, 46, 46) forState:UIControlStateNormal];
    [_btn_Search2 setTitle:@"请选择" forState:UIControlStateNormal];
    _btn_Search2.tag=1002;
    _btn_Search2.titleLabel.font = [UIFont systemFontOfSize:14];
    _btn_Search2.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    _btn_Search2.frame=CGRectMake(100, 33+83, G_SCREENWIDTH-110, 50);
    
    
    _moneyTf=[[UITextField alloc]init];
    
    
    [self setTitle:@"" andTextField:_moneyTf WithPlaceholder:@"转账金额范围1-50000" and:UIKeyboardTypeDecimalPad andIndex:0];
    
    _mimaTf=[[UITextField alloc]init];
    [self setTitle:@"" andTextField:_mimaTf WithPlaceholder:@"请输入资金密码" and:UIKeyboardTypeDefault andIndex:1];
    _mimaTf.secureTextEntry = YES;
    
    UITapGestureRecognizer *singleTapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeKeyboard:)];
    singleTapGesture.numberOfTapsRequired = 1;
    singleTapGesture.cancelsTouchesInView = NO;
    [self.view  addGestureRecognizer:singleTapGesture];
    
    
    _lab_tip=[[UILabel alloc]init];
    _lab_tip.font=[UIFont systemFontOfSize:FONTTIP];
    [self.view addSubview:_lab_tip];
    _lab_tip.numberOfLines=0;
    _lab_tip.textColor=RGB(136,136,136);
    [self setLabelSpace:_lab_tip withValue:TIP withFont:[UIFont systemFontOfSize:FONTTIP]];
    
    [_lab_tip mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left).offset(L_SPACE);
        make.right.equalTo(self.view.mas_right).offset(-L_SPACE);
        make.top.equalTo(self.view.mas_top).offset(325);
    }];
    
    UIButton * footer = [[UIButton alloc]init];
    [self setFooter:footer];
}

#pragma mark - gesture actions
- (void)closeKeyboard:(UITapGestureRecognizer *)recognizer {
    [self.view endEditing:YES];
}

-(void)SetUIWithBack:(UIView *)back andyuE1:(UILabel *)yuE1 andyuENum1:(UILabel *)yuENum1 andZhuanChuBtn:(UIButton *)btn_Search andTag:(NSInteger)tag {
    
    
    UIView * upView = [[UIView alloc]init];
    upView.backgroundColor=[UIColor clearColor];
    [back addSubview:upView];
    upView.frame = CGRectMake(0, 0, G_SCREENWIDTH, 33);
    
    
    yuE1.text = @"余额(元)";
    yuE1.font = [UIFont systemFontOfSize:12];
    yuE1.textColor = RGB(114, 112, 113);
    [upView addSubview:yuE1];
    [yuE1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(upView.mas_top).offset(0);
        make.left.equalTo(upView.mas_left).offset(26);
        make.bottom.equalTo(upView.mas_bottom).offset(0);
    }];
    
    
    yuENum1.text = @"--";
    yuENum1.font = [UIFont systemFontOfSize:14];
    yuENum1.textColor = [UIColor colorWithRed:223.997/255.0 green:81.9987/255.0 blue:117.998/255.0 alpha:1];
    [upView addSubview:yuENum1];
    [yuENum1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(upView.mas_top).offset(0);
        make.left.equalTo(yuE1.mas_right).offset(5);
        make.bottom.equalTo(upView.mas_bottom).offset(0);
    }];
    
    UIView *downView = [[UIView alloc] init];
    downView.frame = CGRectMake(10,33,G_SCREENWIDTH-20,50);
    downView.backgroundColor = [UIColor whiteColor];
    downView.layer.cornerRadius=6;
    [downView clipsToBounds];
    [back  addSubview:downView];
    
    //转出账户
    UILabel * label= [[UILabel alloc] init];
    if (tag==1001) {
        label.text = @"转出账户";
    }else if (tag==1002){
        label.text = @"转入账户";
    }
    label.textAlignment=NSTextAlignmentLeft;
    label.font = [UIFont systemFontOfSize:14];
    label.textColor = [UIColor colorWithRed:45.9995/255.0 green:45.9995/255.0 blue:45.9995/255.0 alpha:1];
    [downView addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(downView.mas_top).offset(0);
        make.left.equalTo(downView.mas_left).offset(13);
        make.bottom.equalTo(downView.mas_bottom).offset(0);
        make.width.mas_equalTo(60);
    }];
    
    
    UIImageView * arrow=[[UIImageView alloc]init];
    [btn_Search addSubview:arrow];
    arrow.image=[UIImage imageNamed:@"person-icon-more"];
    arrow.userInteractionEnabled=NO;
    [arrow mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(btn_Search.mas_centerY).offset(0);
        make.height.mas_equalTo(16);
        make.width.mas_equalTo(9);
        make.right.equalTo(btn_Search.mas_right).offset(-10);
    }];
    
    
    
}


-(void)setFooter:(UIButton *)btn{
    [self.view addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left).offset(10);
        make.right.equalTo(self.view.mas_right).offset(-10);
        make.top.equalTo(_lab_tip.mas_bottom).offset(15);
        make.height.mas_equalTo(50);
    }];
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [btn setTitle:@"转账" forState:UIControlStateNormal];
    btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    btn.contentEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0);
    btn.backgroundColor=MC_THEME_COLOR;
    
    [btn addTarget:self action:@selector(zhuanzhangBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    btn.layer.cornerRadius=5.0;
    btn.clipsToBounds=YES;
    
}

#pragma mark-转账
-(void)zhuanzhangBtnClick:(UIButton *)btn{
    
    //    TranseferType    是    Int    交易方向
    //    TranseferMoney    是    String    转账金额
    //    UserName    是    String    用户名
    //    PayPassWord    是    String    支付密码
    //    ID    是    Int    第三方平台ID
    
    if ([self.selected1.ThirdpartyText isEqualToString:@"请选择"]||[self.selected2.ThirdpartyText isEqualToString:@"请选择"]) {
        [SVProgressHUD showInfoWithStatus:@"请选择资金去向！"];
        return;
    }
    
    if (_moneyTf.text.length<1) {
        [SVProgressHUD showInfoWithStatus:@"请输入转账金额！"];
        return;
    }
    
    if (_mimaTf.text.length<1) {
        [SVProgressHUD showInfoWithStatus:@"请输入资金密码！"];
        return;
    }
    
    if ([_moneyTf.text floatValue]>_DrawMaxMoney) {
        [SVProgressHUD showInfoWithStatus:@"余额不足！"];
        return;
    }
    
    
    
    NSDictionary * dic;
    if ([self.selected1.ThirdpartyText isEqualToString:@"彩票账户"]) {
        //（彩票 -> 第三方）
        dic= @{
               @"TranseferType":self.selected2.LotteryToThirdParty,
               @"TranseferMoney":_moneyTf.text,
               @"UserName":[[NSUserDefaults standardUserDefaults] objectForKey:@"UserName"],
               @"PayPassWord":_mimaTf.text,
               @"ID":self.selected2.ThirdpartyValue
               
               };
    }else{
        //（第三方 -> 彩票）
        dic= @{
               @"TranseferType":self.selected1.ThirdPartyToLottery,
               @"TranseferMoney":_moneyTf.text,
               @"UserName":[[NSUserDefaults standardUserDefaults] objectForKey:@"UserName"],
               @"PayPassWord":_mimaTf.text,
               @"ID":self.selected1.ThirdpartyValue
               
               };
    }
    [BKIndicationView showInView:self.view];
    MCThirdPartyToTransferModel * thirdPartyToTransferModel = [[MCThirdPartyToTransferModel alloc]initWithDic:dic];
    
    self.thirdPartyToTransferModel = thirdPartyToTransferModel;
    [thirdPartyToTransferModel refreashDataAndShow];
    thirdPartyToTransferModel.callBackSuccessBlock = ^(id manager) {
        //        {
        //            DataCount = 0;
        //            OrderState = "-1";
        //            PageCount = 0;
        //            SystemState = 64;
        //        }
        
        
        [BKIndicationView dismiss];
        [SVProgressHUD showInfoWithStatus:@"转账成功！"];
        //        [self performSelector:@selector(delayMethod) withObject:nil/*可传任意类型参数*/ afterDelay:2.0];
        
        [self delayMethod];
        
        
        
        /*
         
         2018年06月20日
         最终Java改了    后期还需要.net改
         
         NSDictionary * dic = manager;
         
         if ([dic[@"ResultCode"] isEqualToString: @"1"]){
         
         [SVProgressHUD showInfoWithStatus:@"转账成功！"];
         
         
         }else if ([dic[@"OrderState"] isEqualToString: @"-1"] || [dic[@"OrderState"] isEqualToString: @"3"]){
         
         [SVProgressHUD showInfoWithStatus:@"转账金额不足！"];
         
         }else if ([dic[@"OrderState"] isEqualToString: @"-3"]){
         
         [SVProgressHUD showInfoWithStatus:@"支付密码错误！"];
         
         }else if ([dic[@"OrderState"] isEqualToString: @"-8"]){
         
         [SVProgressHUD showInfoWithStatus:@"当前用户已被冻结 无法进行转账操作！"];
         
         }else if ([dic[@"OrderState"] isEqualToString: @"-10"]){
         
         [SVProgressHUD showInfoWithStatus:@"测试用户不能转账！"];
         
         }else if ([dic[@"OrderState"] isEqualToString: @"0"]){
         
         [SVProgressHUD showInfoWithStatus:@"系统异常！"];
         
         }else if ([dic[@"OrderState"] isEqualToString: @"1"]){
         
         [SVProgressHUD showInfoWithStatus:@"账号被禁用！"];
         
         }else if ([dic[@"OrderState"] isEqualToString: @"2"]){
         
         [SVProgressHUD showInfoWithStatus:@"账号不存在！"];
         
         }else if ([dic[@"OrderState"] isEqualToString: @"4"]){
         
         [SVProgressHUD showInfoWithStatus:@"密码错误！"];
         
         }else if ([dic[@"OrderState"] isEqualToString: @"5"]){
         
         [SVProgressHUD showInfoWithStatus:@"无效的转账金额！"];
         
         }else if ([dic[@"OrderState"] isEqualToString: @"6"]){
         
         [SVProgressHUD showInfoWithStatus:@"未创建游戏！"];
         }
         
         */
    };
    
    thirdPartyToTransferModel.callBackFailedBlock = ^(id manager, NSString *errorCode) {
        [BKIndicationView dismiss];
    };
}

-(void)delayMethod{
    
    //     [self relayMoneyWithModel:self.selected1 andIndex:1];
    //     [self relayMoneyWithModel:self.selected2 andIndex:2];
    MCShowInfoModel * model0 = [[MCShowInfoModel alloc]init];
    model0.ThirdpartyText = @"请选择";
    
    self.selected1=model0;
    self.selected2=model0;
    
    self.yuENum1.text=@"--";
    self.yuENum2.text=@"--";
    
    _moneyTf.text=@"";
    _mimaTf.text=@"";
    
    [_btn_Search1 setTitle:@"请选择" forState:UIControlStateNormal];
    [_btn_Search2 setTitle:@"请选择" forState:UIControlStateNormal];
    
    
}

-(void)relayMoneyWithModel:(MCShowInfoModel *)t andIndex:(NSInteger)index{
    __weak __typeof__ (self) wself = self;
    
    if (index==1) {
        wself.yuENum1.text=@"--";
        wself.yuENum2.text=@"--";
    }else if (index==2){
        wself.yuENum2.text=@"--";
    }
    
    if ([t.ThirdpartyText isEqualToString:@"彩票账户"]) {
        //  查询用户余额及冻结金额
        MCUserMoneyModel * userMoneyModel=[MCUserMoneyModel sharedMCUserMoneyModel];
        [userMoneyModel refreashDataAndShow];
        self.userMoneyModel=userMoneyModel;
        userMoneyModel.callBackSuccessBlock = ^(id manager) {
            
            wself.userMoneyModel.FreezeMoney = manager[@"FreezeMoney"];
            wself.userMoneyModel.LotteryMoney = manager[@"LotteryMoney"];
            NSString * LotteryMoney =[NSString stringWithFormat:@"%@",manager[@"LotteryMoney"]];
            if (index==1) {
                
                wself.yuENum1.text=GetRealSNum(LotteryMoney);
                if ([LotteryMoney floatValue]>0.001) {
                    _DrawMaxMoney=[LotteryMoney floatValue];
                    if ([LotteryMoney floatValue]>ZhuanZhangMaxMoney) {
                        _DrawMaxMoney=ZhuanZhangMaxMoney;
                    }
                }else{
                    _DrawMaxMoney=ZhuanZhangMaxMoney;
                }
            }else if (index==2){
                
                wself.yuENum2.text=GetRealSNum(LotteryMoney);
            }
        };
    }else if ([t.ThirdpartyText isEqualToString:@"请选择"]){
        if (index==1) {
            wself.yuENum1.text=@"--";
        }else if (index==2){
            wself.yuENum2.text=@"--";
        }
    }else{
        [BKIndicationView showInView:self.view];
        
        //                    ID    是    Number    第三方平台ID
        //                    UserName    是    String    当前登陆用户名称
        NSDictionary * dic =@{
                              @"ID":t.ThirdpartyValue,
                              @"UserName":[[NSUserDefaults standardUserDefaults] objectForKey:@"UserName"]
                              };
        
        MCGetThirdPartyBalanceModel * getThirdPartyBalanceModel = [[MCGetThirdPartyBalanceModel alloc]initWithDic:dic];
        self.getThirdPartyBalanceModel = getThirdPartyBalanceModel;
        [getThirdPartyBalanceModel refreashDataAndShow];
        getThirdPartyBalanceModel.callBackSuccessBlock = ^(id manager) {
            //                    get_third_party_balance 需要判断返回的Balance是否是-1或者null 如果是  调用一次第三方登录接口然后判断第三方登录URL是否有。有的话余额显示为0 没有余额显示--
            
            
            wself.Balance = [NSString stringWithFormat:@"%@",manager[@"Balance"]];
            
            if ([wself.Balance containsString:@"null"]||[wself.Balance integerValue]<0||wself.Balance.length<1) {
                
                
                MCThdLoginModel * thdModel=[[MCThdLoginModel alloc] init];
                thdModel.ID = dic[@"ID"];
                thdModel.UserName = dic[@"UserName"];;
                [thdModel refreashDataAndShow];
                self.thdLoginModel=thdModel;
                thdModel.callBackSuccessBlock = ^(NSDictionary *manager) {
                    [BKIndicationView dismiss];
                    if ( [manager.allKeys containsObject:@"LoginUrl"] && [manager[@"LoginUrl"] isEqualToString:@""] == NO) {
                        
                        wself.Balance=@"0";
                        
                    }else{
                        wself.Balance=@"--";
                        //                        [SVProgressHUD showInfoWithStatus:@"查询失败！"];
                    }
                    
                    wself.Balance=GetRealSNum(wself.Balance);
                    if (index==1) {
                        wself.yuENum1.text=wself.Balance;
                        if ([wself.Balance floatValue]>=0) {
                            _DrawMaxMoney=[wself.Balance floatValue];
                            if ([wself.Balance floatValue]>ZhuanZhangMaxMoney) {
                                _DrawMaxMoney=ZhuanZhangMaxMoney;
                            }
                        }else{
                            _DrawMaxMoney=ZhuanZhangMaxMoney;
                        }
                    }else if (index==2){
                        wself.yuENum2.text=wself.Balance;
                    }
                };
                thdModel.callBackFailedBlock = ^(ApiBaseManager *manager, NSString *errorCode) {
                    
                    [BKIndicationView dismiss];
                };
                
            }else{
                [BKIndicationView dismiss];
                wself.Balance=GetRealSNum(wself.Balance);
                if (index==1) {
                    wself.yuENum1.text=wself.Balance;
                    if ([wself.Balance floatValue]>=0) {
                        _DrawMaxMoney=[wself.Balance floatValue];
                        if ([wself.Balance floatValue]>ZhuanZhangMaxMoney) {
                            _DrawMaxMoney=ZhuanZhangMaxMoney;
                        }
                    }else{
                        _DrawMaxMoney=ZhuanZhangMaxMoney;
                    }
                }else if (index==2){
                    wself.yuENum2.text=wself.Balance;
                }
            }
            
        };
        
        getThirdPartyBalanceModel.callBackFailedBlock = ^(id manager, NSString *errorCode) {
            [BKIndicationView dismiss];
        };
    }
}

-(void)btn_SearchAction:(UIButton *)btn{
    
    __weak __typeof__ (self) wself = self;
    MCThirdPartyShowInfoModel *thirdPartyShowInfoModel = [MCThirdPartyShowInfoModel sharedMCThirdPartyShowInfoModel];
    
    
    //转出账户
    if (btn.tag==1001) {
        
        NSMutableArray * marr = [[NSMutableArray alloc]init];
        
        MCShowInfoModel * model0 = [[MCShowInfoModel alloc]init];
        model0.ThirdpartyText = @"请选择";
        [marr addObject:model0];
        
        MCShowInfoModel * model1 = [[MCShowInfoModel alloc]init];
        model1.ThirdpartyText = @"彩票账户";
        [marr addObject:model1];
        
        [marr addObjectsFromArray:thirdPartyShowInfoModel.zhuanzhang_dataArray];
        
        if (thirdPartyShowInfoModel.zhuanzhang_dataArray.count>0) {
            
            MCPaySelectedLotteryPickView *picker = [[MCPaySelectedLotteryPickView alloc]init];
            picker.Type=MCPaySelectedPickViewType_MCShowInfoModel;
            picker.title=@"选择平台";
            picker.dataSource = marr;
            picker.getShowInfoModel = ^(MCShowInfoModel *t) {
                
                wself.selected1 = t;
                [wself.btn_Search1 setTitle:t.ThirdpartyText forState:UIControlStateNormal];
                //将转入账户重置
                wself.selected2 = model0;
                wself.yuENum1.text=@"--";
                [wself.btn_Search2 setTitle:model0.ThirdpartyText forState:UIControlStateNormal];
                [wself relayMoneyWithModel:t andIndex:1];
                
            };
            
            [picker show];
            
        }
        
        //转入账户
    }else if (btn.tag==1002){
        
        NSMutableArray * marr = [[NSMutableArray alloc]init];
        MCShowInfoModel * model0 = [[MCShowInfoModel alloc]init];
        model0.ThirdpartyText = @"请选择";
        [marr addObject:model0];
        
        if ([self.selected1.ThirdpartyText isEqualToString:@"请选择"]) {
            
            MCPaySelectedLotteryPickView *picker = [[MCPaySelectedLotteryPickView alloc]init];
            picker.Type=MCPaySelectedPickViewType_MCShowInfoModel;
            picker.title=@"选择平台";
            picker.dataSource = marr;
            picker.getShowInfoModel = ^(MCShowInfoModel *t) {
                
                wself.selected2 = t;
                [wself.btn_Search2 setTitle:t.ThirdpartyText forState:UIControlStateNormal];
                [wself relayMoneyWithModel:t andIndex:2];
            };
            
            [picker show];
            
        }else if ([self.selected1.ThirdpartyText isEqualToString:@"彩票账户"]){
            
            [marr addObjectsFromArray:thirdPartyShowInfoModel.zhuanzhang_dataArray];
            
            MCPaySelectedLotteryPickView *picker = [[MCPaySelectedLotteryPickView alloc]init];
            picker.Type=MCPaySelectedPickViewType_MCShowInfoModel;
            picker.title=@"选择平台";
            picker.dataSource = marr;
            picker.getShowInfoModel = ^(MCShowInfoModel *t) {
                
                wself.selected2 = t;
                [wself.btn_Search2 setTitle:t.ThirdpartyText forState:UIControlStateNormal];
                [wself relayMoneyWithModel:t andIndex:2];
            };
            
            [picker show];
            
        }else{
            
            MCShowInfoModel * model1 = [[MCShowInfoModel alloc]init];
            model1.ThirdpartyText = @"彩票账户";
            [marr addObject:model1];
            
            MCPaySelectedLotteryPickView *picker = [[MCPaySelectedLotteryPickView alloc]init];
            picker.Type=MCPaySelectedPickViewType_MCShowInfoModel;
            picker.title=@"选择平台";
            picker.dataSource = marr;
            picker.getShowInfoModel = ^(MCShowInfoModel *t) {
                
                wself.selected2 = t;
                [wself.btn_Search2 setTitle:t.ThirdpartyText forState:UIControlStateNormal];
                [wself relayMoneyWithModel:t andIndex:2];
            };
            
            [picker show];
        }
    }
}

-(void)setTitle:(NSString *)title andTextField:(UITextField*)textField WithPlaceholder:(NSString *)placeholder and:(UIKeyboardType)type andIndex:(int)index{
    
    CGFloat padding=50;
    CGFloat Top = 198;
    
    UIView * view = [[UIView alloc]init];
    [self.view addSubview:view];
    view.frame=CGRectMake(10, Top+index*(padding+10), G_SCREENWIDTH-20, padding);
    view.layer.cornerRadius=6;
    view.backgroundColor=[UIColor whiteColor];
    [view clipsToBounds];
    
    [view addSubview:textField];
    textField.frame=CGRectMake(10, 0, G_SCREENWIDTH-40, padding);
    textField.placeholder=placeholder;
    textField.borderStyle = UITextBorderStyleNone;
    textField.backgroundColor=[UIColor whiteColor];
    textField.font = [UIFont systemFontOfSize:14];
    textField.textColor = RGB(40, 40, 40);
    textField.textAlignment = NSTextAlignmentLeft;
    textField.returnKeyType = UIReturnKeyDone;
    textField.keyboardType = type;
    [textField setValue:RGB(181, 181, 181) forKeyPath:@"_placeholderLabel.textColor"];
    [textField setValue:[UIFont systemFontOfSize:14] forKeyPath:@"_placeholderLabel.font"];
    [textField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:(UIControlEventEditingChanged)];
    
}

-(void)textFieldDidChange:(UITextField *)textField{
    if (textField==self.moneyTf) {
        if (textField.text.length == 1 && [textField.text isEqualToString:@"."]) {
            //            textField.text = @"0.";
            textField.text = @"";
        }
        if (textField.text.length == 1 && [textField.text isEqualToString:@"0"]) {
            //            textField.text = @"0.";
            textField.text = @"";
        }
        NSArray *arr = [textField.text componentsSeparatedByString:@"."];
        
        float max = [textField.text floatValue];
        if (max>= _DrawMaxMoney) {
            max = _DrawMaxMoney;
            NSString * DrawMaxMoney = [NSString stringWithFormat:@"%.2f",_DrawMaxMoney];
            textField.text =GetRealSNum(DrawMaxMoney);;
        }
        if (arr.count >1) {
            
            NSString *str = arr[1];
            if (str.length > 2) {
                str = [str substringWithRange:NSMakeRange(0, 2)];
            }
            textField.text = [NSString stringWithFormat:@"%@.%@",arr[0],str];
            //            textField.text = [NSString stringWithFormat:@"%@",arr[0]];
            
            NSString * str1=arr[0];
            if ([str1 isEqualToString:[NSString stringWithFormat:@"%.f",_DrawMaxMoney]]) {
                textField.text = [NSString stringWithFormat:@"%.f",_DrawMaxMoney];
            }
        }
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
//给UILabel设置行间距和字间距
-(void)setLabelSpace:(UILabel*)label withValue:(NSString*)str withFont:(UIFont*)font {
    NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
    paraStyle.lineBreakMode = NSLineBreakByCharWrapping;
    paraStyle.alignment = NSTextAlignmentLeft;
    paraStyle.lineSpacing = UILABEL_LINE_SPACE; //设置行间距
    paraStyle.hyphenationFactor = 1.0;
    paraStyle.firstLineHeadIndent = 0.0;
    paraStyle.paragraphSpacingBefore = 0.0;
    paraStyle.headIndent = 0;
    paraStyle.tailIndent = 0;
    //设置字间距 NSKernAttributeName:@1.5f
    NSDictionary *dic = @{NSFontAttributeName:font, NSParagraphStyleAttributeName:paraStyle, NSKernAttributeName:@UILABEL_Kern_SPACE
                          };
    
    NSAttributedString *attributeStr = [[NSAttributedString alloc] initWithString:str attributes:dic];
    label.attributedText = attributeStr;
}


//计算UILabel的高度(带有行间距的情况)
+(CGFloat)getSpaceLabelHeight:(NSString*)str withFont:(UIFont*)font withWidth:(CGFloat)width {
    NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
    paraStyle.lineBreakMode = NSLineBreakByCharWrapping;
    paraStyle.alignment = NSTextAlignmentLeft;
    paraStyle.lineSpacing = UILABEL_LINE_SPACE;
    paraStyle.hyphenationFactor = 1.0;
    paraStyle.firstLineHeadIndent = 0.0;
    paraStyle.paragraphSpacingBefore = 0.0;
    paraStyle.headIndent = 0;
    paraStyle.tailIndent = 0;
    NSDictionary *dic = @{NSFontAttributeName:font, NSParagraphStyleAttributeName:paraStyle, NSKernAttributeName:@UILABEL_Kern_SPACE
                          };
    
    CGSize size = [str boundingRectWithSize:CGSizeMake(width, 100) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil].size;
    return size.height;
}
/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
